package com.example.main;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.example.main.mypackage.ContainerViewLayout;
import com.example.main.mypackage.MyChildView;
import com.tencent.mmkv.MMKV;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

public class MainActivity extends FragmentActivity {


    private ContainerViewLayout view_container;
    private MyChildView myChildView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);

        view_container = findViewById(R.id.view_container);
        myChildView = new MyChildView(this);
        view_container.addView(myChildView);
        myChildView.setContent("对对对");
        myChildView.setBackgroundColor(getResources().getColor(R.color.colorAccent));

        myChildView = new MyChildView(this);
        view_container.addView(myChildView);
        myChildView.setContent("对对对2");

        myChildView.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        myRequetPermission();


        String rootDir = MMKV.initialize(this);
        System.out.println("mmkv root: " + rootDir);
        Log.i("dddd", rootDir);

        MMKV ding = MMKV.mmkvWithID("dingjiahui");
        ding.encode("jia", true);
        Log.i("cccc", ding.decodeString("jia") + "");


        MMKV kv = MMKV.defaultMMKV();

        kv.encode("bool", true);
        boolean bValue = kv.decodeBool("bool");

        kv.encode("int", Integer.MIN_VALUE);
        int iValue = kv.decodeInt("int");

        kv.encode("string", "Hello from mmkv");
        String str = kv.decodeString("string");

        int a = 0;
        a = 0;


    }

    private void myRequetPermission() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        } else {
            Toast.makeText(this, "您已经申请了权限!", Toast.LENGTH_SHORT).show();
        }
    }
}
